import React from 'react'
import {inject, observer} from 'mobx-react'
import {message} from 'antd'

const HOCStoreShoppingProcess = WarpComponent=>{
    @inject('setStoreInfo')
    @observer
    class ElementComponent extends React.Component{
        componentDidMount(){
            let {getStoreShoppingProcess} = this.props.setStoreInfo
            //查询购物流程
            getStoreShoppingProcess().then(data=>{
                if (data.data.code === 200) {
                    let allData = data.data.data[0]
                    this.setForm(allData)
                }else{
                    message.error('请求数据失败')
                }
            })
        }
        setForm=(obj)=>{
            let {formOne} = this.refs.form.refs
            formOne.setFieldsValue(obj)
        }
        submit=()=>{
            let {updateStoreShoppingProcess} = this.props.setStoreInfo
            let {formOne} = this.refs.form.refs
            let integralStatu = formOne.getFieldValue('integralStatu') //是否使用积分
            let coupon = formOne.getFieldValue('coupon') //是否使用优惠券
            let balance = formOne.getFieldValue('balance') //是否使用余额
            let orderStatu = formOne.getFieldValue('orderStatu') //备注
            let amountMin = formOne.getFieldValue('amountMin') //购物最小金额
            let reduceStatu = formOne.getFieldValue('reduceStatu') //减小购物时机
            let obj = {
                storeShoppingProcess:1,
                integralStatu,
                coupon,
                balance,
                orderStatu,
                amountMin,
                reduceStatu
            }
            updateStoreShoppingProcess(obj).then(data=>{
                if (data.data.code === 200) {
                    message.success('更新数据成功')
                }else{
                    message.error('更新数据失败')
                }
            })
        }
        render() {
            let methods = {
                submit:this.submit
            }
            return (
                <div>
                    <WarpComponent ref='form' {...methods}></WarpComponent>
                </div>
            );
        }
    }
    return ElementComponent
}

export default HOCStoreShoppingProcess